package ar.com.pragmatia.lanacion.utils;

import java.util.Calendar;

public class Format {
	
	public static String getTime() {
	    // get the current date
	    final Calendar c = Calendar.getInstance();
	    return c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
	}

	
	public static String getFrenchDate() {
	    // get the current date
	    final Calendar c = Calendar.getInstance();
	    return Format.getFrenchDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
	}
    
	public static String getFrenchDate(int year, int month, int day) {
		return Format.getDate(year, month, day, "dd/mm/yyyy");
	}
	
	public static String getYearFromFrenchDate(String date) {
		return Format.getYear(date, "dd/mm/yyyy");
	}
	public static String getMonthFromFrenchDate(String date) {
		return Format.getMonth(date, "dd/mm/yyyy");
	}
	public static String getDayFromFrenchDate(String date) {
		return Format.getDay(date, "dd/mm/yyyy");
	}
	
	public static String getYear(String date, String format) {
		if (format.equals("dd/mm/yyyy")) {
			return date.substring(6);
		} else {
			return null;
		}
	}
	public static String getMonth(String date, String format) {
		if (format.equals("dd/mm/yyyy")) {
			return date.substring(3, 5);
		} else {
			return null;
		}
	}
	public static String getDay(String date, String format) {
		if (format.equals("dd/mm/yyyy")) {
			return date.substring(0, 2);
		} else {
			return null;
		}
	}
	
	public static String getDate(int year, int month, int day, String format) {
		
		String sDay, sMonth;
		if (day <= 9) {
			sDay = "0" + String.valueOf(day); 
		} else {
			sDay = String.valueOf(day); 
		}
		
	    // Month is 0 based so add 1 to "normalize"
		month++;
		
		if (month <= 9) {
			sMonth = "0" + String.valueOf(month); 
		} else {
			sMonth = String.valueOf(month); 
		}
		
		if (format.equals("dd/mm/yyyy")) {
			return sDay + "/" + sMonth + "/" + String.valueOf(year);
		} else {
			return null;
		}

	}

}
